import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useAdStore = defineStore('ad', () => {
  // 广告配置
  const adConfig = ref({
    banner: 'ad-banner-id',
    interstitial: 'ad-interstitial-id',
    rewardVideo: 'ad-reward-video-id',
    native: 'ad-native-id'
  })
  
  // 广告策略
  const adStrategy = ref({
    browseCount: 5,              // 每浏览5张显示插屏
    timeInterval: 120000,         // 每2分钟显示一次（毫秒）
    downloadRequireAd: true,      // 下载需要看广告
    startupDelay: 5000            // 启动页广告时长（毫秒）
  })
  
  // 广告展示统计
  const adStats = ref({
    banner: { show: 0, click: 0 },
    interstitial: { show: 0, click: 0 },
    rewardVideo: { show: 0, click: 0 },
    native: { show: 0, click: 0 }
  })
  
  // 设置广告配置
  function setAdConfig(config) {
    adConfig.value = { ...adConfig.value, ...config }
  }
  
  // 设置广告策略
  function setAdStrategy(strategy) {
    adStrategy.value = { ...adStrategy.value, ...strategy }
  }
  
  // 记录广告展示
  function recordAdShow(type) {
    if (adStats.value[type]) {
      adStats.value[type].show++
    }
  }
  
  // 记录广告点击
  function recordAdClick(type) {
    if (adStats.value[type]) {
      adStats.value[type].click++
    }
  }
  
  // 获取广告统计
  function getAdStats() {
    return adStats.value
  }
  
  return {
    adConfig,
    adStrategy,
    adStats,
    setAdConfig,
    setAdStrategy,
    recordAdShow,
    recordAdClick,
    getAdStats
  }
})

